import Vue from 'vue'
import VueRouter from 'vue-router'

// 引入登录页面组件
// import Login from '../views/Login'
// import Layout from '../views/Layout'
// import Home from '../views/Layout/Home'
// import User from '../views/Layout/User'
// import Search from '../views/Search'
// import Searchresult from '../views/Search/SearchResult.vue'
// import Articledetail from '../views/Article/id.vue'
// import useredit from '../views/useredit'
// import Chat from '../views/Chat'

// --------------------懒加载-----------------

import Login from '../views/Login'
import Layout from '../views/Layout'
import Home from '../views/Layout/Home'

const User = () => import('../views/Layout/User')
const Search = () => import('../views/Search')
const Searchresult = () => import('../views/Search/SearchResult.vue')
const Articledetail = () => import('../views/Article/id.vue')
const useredit = () => import('../views/useredit')
const Chat = () => import('../views/Chat')

// ---------------- 分割线 ----------------------
Vue.use(VueRouter)
const routes = [
  // 首页重定向
  {
    path: '/',
    redirect: '/layout'
  },
  // 登录路由
  {
    path: '/login',
    component: Login
  },
  // 首页路由
  {
    path: '/layout',
    component: Layout,
    redirect: '/layout/home',
    children: [
      {
        path: 'home',
        component: Home,
        // 记录用户滚动距离
        meta: {
          scrollY: 0
        }
      },
      {
        path: 'user',
        component: User
      }
    ]
  },
  // 搜索路由
  {
    path: '/search',
    component: Search
  },
  // 搜索结果路由
  {
    path: '/searchresult/:keyword',
    name: 'gotoFn',
    component: Searchresult
  },
  // 搜索文章详情路由
  {
    path: '/article',
    component: Articledetail
  },
  // 个人中心路由
  {
    path: '/user/edit',
    component: useredit
  },
  // 机器人路由
  {
    path: '/chat',
    component: Chat
  }
]

const router = new VueRouter({
  routes
})

export default router
